#!/bin/bash

# Make sure input is provided
EXPECTED_ARGS=1
E_BADARGS=65

if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: `basename $0` {arg}"
  exit $E_BADARGS
fi

appFolder=$1

# Make a directory for this output
#scriptOutputlocation=$appFolder"_output" 
scriptOutputlocation="Apache_output" 
mkdir -p $scriptOutputlocation
chmod 777 $scriptOutputlocation


echo $scriptOutputlocation


# Look through all files

FILES=$(find $appFolder -type f -name '*.c')
for f in $FILES
do
let cnt="cnt + 1"
	filename=$f
#	outpufile=${filename/.c/.i}  # This is the preprocessed file to be analyzed
baseFileName=$(basename $filename)
outpufile=${baseFileName/.c/.i}  # This is the preprocessed file to be analyzed



#	echo $outpufile

	# gcc -E $filename -o kraw.i
	# gcc -E $filename -o $outputfile

	gcc -E $filename -o $scriptOutputlocation"/"$outpufile





	# move the files?
done
# Compile them all


### Todo
# Once this works, make sure to check in to the project SVN
# 


